// http://api.douban.com/v2/movie/subject/1764796

const rp = require('request-promise-native')

async function fetchMovie (item) {
  const url = `http://api.douban.com/v2/movie/subject/${item.doubanId}`
  const res = await rp(url)

  return res
}

;(async() => {
  let movies = [
    { 
      doubanId: 30242146,
      title: '与不是A君的你',
      rate: 6.9,
      poster: 'https://img1.doubanio.com/view/photo/l_ratio_poster/public/p2532486138.jpg' },
    { doubanId: 27072748,
      title: '模范警察',
      rate: 6.8,
      poster: 'https://img1.doubanio.com/view/photo/test/public/p2530764198.jpg' 
    }
  ]

  movies.map(async movie => {
    let movieData = await fetchMovie(movie)

    try {
      movieData = JSON.parse(movieData)
      console.log(movieData.tags)
      console.log(movieData.summary)
    } catch (err) {
      console.log(err)
    }
  })
})()

// const movieData = await fetchMovie()